cmake_minimum_required(VERSION 3.10)
PROJECT(TEST)

SET(CMAKE_C_FLAGS "-Wall  -std=c++17")
SET(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -std=c++17 ")


# 设置包含目录
set(INCLUDE_DIR ${CMAKE_SOURCE_DIR}/inc)

# 递归查找 inc 目录下所有的头文件
file(GLOB_RECURSE ALL_HEADER_FILES "${INCLUDE_DIR}/*.h")

# 打印所有找到的头文件
message(STATUS "Found header files:")
foreach(_headerFile ${ALL_HEADER_FILES})
    message(STATUS "${_headerFile}")
endforeach()

# 获取所有包含头文件的目录
set(HEADER_DIRS "")
foreach(_headerFile ${ALL_HEADER_FILES})
    get_filename_component(_dir ${_headerFile} PATH)
    list(APPEND HEADER_DIRS ${_dir})
endforeach()
list(REMOVE_DUPLICATES HEADER_DIRS)

# 将头文件目录添加到 include 路径
foreach(_dir ${HEADER_DIRS})
    include_directories(${_dir})
endforeach()

# 设置源文件目录
set(SOURCE_DIR ${CMAKE_SOURCE_DIR}/src)

# 递归查找src目录下所有的cpp文件
file(GLOB_RECURSE SOURCE_FILES "${SOURCE_DIR}/*.cpp")

# 打印所有找到的源文件
message(STATUS "Found source files:")
foreach(_sourceFile ${SOURCE_FILES})
    message(STATUS "${_sourceFile}")
endforeach()


# # 将所有源文件编译成一个共享库
# add_library(arc_dump_lib SHARED ${SOURCE_FILES})

# 设置库文件目录
set(LIB_DIR ${CMAKE_SOURCE_DIR}/lib)

# 递归查找lib目录下所有的so文件
file(GLOB_RECURSE LIB_FILES "${LIB_DIR}/*")

# 打印所有找到的库文件
message(STATUS "Found library files:")
foreach(_libFile ${LIB_FILES})
    message(STATUS "${_libFile}")
endforeach()

# 将所有的库文件链接到目标
foreach(_libFile ${LIB_FILES})
    list(APPEND EXTRA_LIBS ${_libFile})
endforeach()


# 添加可执行文件
add_executable(test             test/test.cpp
                                                                                ${SOURCE_FILES})
target_link_libraries(  test 
                                            ${EXTRA_LIBS} 
                                            pthread
)



#  add_dependencies(test cppcheck)

